export function useColumn() {
  const { auth } = useAuth();
  const showRoleColumn = () => {
    return auth([
      'v-edit',
      'v-clear',
    ]);
  };
  const allColumns: any = [
    {
      title: '分支局',
      dataIndex: 'area',
      width: '15%',
      align: 'center',
      customRender: ({ record }: { record: any }) => {
        return record.area || record.AREA;
      },
    },
    {
      title: '合同号',
      dataIndex: 'account',
      width: '10%',
      align: 'center',
      customRender: ({ record }: { record: any }) => {
        return record.account || record.ACCOUNT;
      },
    },
    {
      title: '打印周期',
      dataIndex: 'printmonth',
      width: '10%',
      align: 'center',
      customRender: ({ record }: { record: any }) => {
        return record.printmonth || record.PRINTMONTH;
      },
      sorter: (a: VAPI.DataItem, b: VAPI.DataItem) => Number(a.printmonth) - Number(b.printmonth),
    },
    {
      title: '专票周期',
      dataIndex: 'billmonth',
      width: '10%',
      align: 'center',
      customRender: ({ record }: { record: any }) => {
        return record.billmonth || record.BILLMONTH;
      },
      sorter: (a: VAPI.DataItem, b: VAPI.DataItem) => Number(a.billmonth) - Number(b.billmonth),
    },
    {
      title: '专票流水号',
      dataIndex: 'invoice',
      width: '10%',
      align: 'center',
      customRender: ({ record }: { record: any }) => {
        return record.invoice || record.INVOICE;
      },
    },
    {
      title: '金额',
      dataIndex: 'amount',
      width: '7%',
      align: 'center',
      customRender: ({ record }: { record: any }) => {
        return record.amount || record.AMOUNT;
      },
    },
    {
      title: '是否已打印',
      dataIndex: 'printflag',
      width: '10%',
      align: 'center',
      customRender: ({ record }: { record: any }) => {
        return record.printflag || record.PRINTFLAG;
      },
      // 定义筛选菜单项
      filters: [
        {
          text: '是',
          value: '是',
        },
        {
          text: '否',
          value: '否',
        },
      ],
      filterMultiple: false,
      onFilter: (value: string, record: VAPI.DataItem) => record.printflag.indexOf(value) === 0,
    },
    {
      title: '添加人员',
      dataIndex: 'operator',
      width: '8%',
      align: 'center',
      customRender: ({ record }: { record: any }) => {
        return record.operator || record.OPERATOR;
      },
    },
    {
      title: '创建日期',
      dataIndex: 'created',
      width: '10%',
      align: 'center',
      customRender: ({ record }: { record: any }) => {
        return record.created || record.CREATED;
      },
      sorter: (a: VAPI.DataItem, b: VAPI.DataItem) => Number(a.created) - Number(b.created),
    },
    {
      title: '操作',
      dataIndex: 'operation',
      key: 'lastColumn',
      width: '10%',
      align: 'center',
    },
  ];
  const columns: any = computed(() => {
    return allColumns.filter((column: any) => {
      const flag = showRoleColumn();
      if (!flag && column.title === '操作') {
        return false;
      }
      return true;
    });
  });
  return {
    columns,
  };
}
